<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>弓友之家</title>
    <link rel="stylesheet" href="css/mui.css" />
    <link rel="stylesheet" href="fonts/iconfont.css" />
    <link rel="stylesheet" href="css/style.css" />
    <style>
    	.index-goods{background: none;}
    	#goods{top: 44px;}
    	.mui-segmented-control.mui-scroll-wrapper .mui-control-item{padding: 0 10px;}
    	.mui-segmented-control.mui-scroll-wrapper{height: 40px; padding: 0 10px;}
    </style>
</head>
<body>
	<div class="mui-content">
		<div class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
		    <div class="mui-scroll goods-title">
		        
		    </div>
		</div>
		<div class="mui-scroll-wrapper" id="goods">
		    <div class="mui-scroll">
		        <div class="index-goods">
					<div class="mui-clearfix">
						
					</div>
				</div>
		    </div>
		</div>
	</div>
	<br /><br /><br />
	<!--兑换弹出框-->
	<!--<div class="buy-box mui-hidden">
		<div class="text">您是想如何购买商品？</div>
		<div class="mui-row">
			<div class="mui-col-xs-6">
				<button type="button" data-gid="" class="dhbtn">立即兑换</button>
			</div>
			<div class="mui-col-xs-6">
				<button type="button" data-tburl="" class="dhbtn1">立即购买</button>
			</div>
		</div>
	</div>-->
	<script type="text/javascript" src="js/mui.min.js" ></script>
	<script type="text/javascript" src="js/jquery-1.8.3.min.js" ></script>
	<script type="text/javascript" src="js/jquery.SuperSlide.2.1.1.js" ></script>
	<script type="text/javascript" src="js/common.js" ></script>
	<script type="text/javascript" charset="utf-8">
      	mui.init();
      	var key=0;
      	mui.ajax(H_SRC+'/amier/index/cates',{
			data:{
				token:token
			},
			dataType:'json',
			type:'post',
			timeout:10000,             
			success:function(data){
				var dataurl=data.data;
				if(data.code == 1){
					for(var i=0;i<dataurl.cate.length;i++){
						$(".goods-title").append('<a class="mui-control-item" data-id="'+dataurl.cate[i].id+'">'+dataurl.cate[i].cateName+'</a>')
					}
					$(".goods-title a").eq(0).addClass("mui-active");
					key=$(".goods-title a").eq(0).attr("data-id");
					
					goodsAll();
				}else{
					mui.toast(data.msg);
				}
			},
			error:function(){
				
			}
		}) 
		
		$(".goods-title").on("tap","a",function(){
			key=$(this).attr("data-id");
			getList()
		})
		
		var page=1;
      	mui.init({ 
		    pullRefresh : {
		        container:"#goods",
		        down : {
		            height:50,
		            auto: true,
		            contentdown : "下拉可以刷新",
		            contentover : "释放立即刷新",
		            contentrefresh : "正在刷新...",
		            callback : getList 
		        },
		        up : { 
		            height:50,
		            auto:false,
		            contentrefresh : "正在加载...",
		            contentnomore:'没有更多数据了',
		            callback : getListByPage 
		        }
		    },
		}); 
		function getList(){
			mui.ajax(H_SRC+'/amier/index/shops_cate',{
				data:{
					token:token,
					page:1,
					key:key
				},
				dataType:'json',//服务器返回json格式数据
				type:'post',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；            
				success:function(data){
					var dataurl=data.data;
					if(data.code == 401)
					{
						mui.openWindow({
							url:'login.html',
							id:'login.html'
						})
					}else if(data.code == 1) 
					{
						var dataurl=data.data;
						var goods="";
						for(var i=0;i<dataurl.length;i++){
							goods+='<div class="one" data-id="'+dataurl[i].id+'">';
							goods+='<a class="img"><img src="'+H_SRC+''+dataurl[i].img+'"/></a>';
							goods+='<div class="text">';
							goods+='<h4 class="mui-ellipsis"><a data-id="'+dataurl[i].id+'" >'+dataurl[i].goodsName+'</a></h4>';
							goods+='<h5 class="mui-clearfix">';
							goods+='<span>￥'+parseInt(dataurl[i].price)+'</span>';
							if(dataurl[i].isShipping==1){
								var by="<i>包邮</i>";
							}else{
								var by=""
							}
							goods+=by+'';
							goods+='<button type="button">立即兑换</button>';
							goods+='</h5></div></div>';
						} 
						$(".index-goods .mui-clearfix").html(goods);
						mui('#goods').pullRefresh().endPulldownToRefresh();
			            //重置上拉
			            mui('#goods').pullRefresh().refresh(true);
			            page = 2;
					}else{ 
						mui.toast(data.msg);
					}
				},
				error:function(){
				}
			}) 
		}
      	function getListByPage(){
		    var _this = this;
		    mui.ajax(H_SRC+'/amier/index/shops_cate',{
				data:{
					page:page,
					token:token,
					key:key
				},
				dataType:'json',//服务器返回json格式数据
				type:'post',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；
				headers:{'Authorization':token},              
				success:function(data){
					var dataurl=data.data;
					if(data.code == 401)
					{
						mui.openWindow({
							url:'login.html',
							id:'login.html'
						})
					}else if(data.code == 1) 
					{
						var dataurl=data.data;
						if(dataurl.length == 0){
			                _this.endPullupToRefresh(true);
			                return false;
			            }
						
						for(var i=0;i<dataurl.length;i++){ 
							var goods="";
							goods+='<div class="one" data-id="'+dataurl[i].id+'">';
							goods+='<a class="img"><img src="'+H_SRC+''+dataurl[i].img+'"/></a>';
							goods+='<div class="text">';
							goods+='<h4 class="mui-ellipsis"><a data-id="'+dataurl[i].id+'" >'+dataurl[i].goodsName+'</a></h4>';
							goods+='<h5 class="mui-clearfix">';
							goods+='<span>￥'+parseInt(dataurl[i].price)+'</span>';
							if(dataurl[i].isShipping==1){
								var by="<i>包邮</i>";
							}else{
								var by=""
							}
							goods+=by+'';
							goods+='<button type="button">立即兑换</button>';
							goods+='</h5></div></div>';
							$(".index-goods .mui-clearfix").append(goods);
						}
						_this.endPullupToRefresh(false);
		            	page++;
					}else{ 
						mui.toast(data.msg);
					}
				},
				error:function(){
				}
			}) 
		}
      	
      	var mask=mui.createMask(callback);
      	function callback(){
      		$(".first-login").addClass("mui-hidden");
      		$(".buy-box").addClass("mui-hidden");
      	}
      	$(".index-goods").on("tap",".one",function(){
      		var gid=$(this).attr("data-id");
//    		var tburl=$(this).attr("data-taobao");
//    		$(".dhbtn").attr("data-gid",gid);
//    		$(".dhbtn1").attr("data-tburl",tburl);
//    		mask.show();
//    		$(".buy-box").removeClass("mui-hidden");
			mui.openWindow({
				url:'goods-list-page.html',
				id:'goods-list-page.html',
				createNew:true,
				show: {
					autoShow: true,
					aniShow: 'slide-in-right',
					duration: 200,
				},
				extras:{
					gid:gid
				}
			});
      	})
//    	$(".dhbtn").on("tap",function(){ 
//    		var gid=$(this).attr("data-gid");
//    		mui.openWindow({
//				url:'dhaddress.html',
//				id:'dhaddress.html',
//				createNew:true,
//				extras:{
//					gid:gid
//				},
//				show: {
//					autoShow: true,
//					aniShow: 'slide-in-right',
//					duration: 200
//				}
//			});
//    	});
//    	$(".dhbtn1").on("tap",function(){
//    		var link=$(this).attr("data-tburl");
//    		mui.openWindow({
//				url:link,
//				id:link,
//				createNew:true,
//				show: {
//					autoShow: true,
//					aniShow: 'slide-in-right',
//					duration: 200
//				}
//			});
//    	})
    </script>
</body>
</html>